package com.tanhua.dubbo.api.impl;

import com.tanhua.domain.mongo.UserLevel;
import com.tanhua.dubbo.api.UserLevelApi;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.util.List;

@Service
public class UserLevelApiImpl implements UserLevelApi {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public UserLevel findByUid(Long userId) {
        Query query = new Query(Criteria.where("uid").is(userId));
        UserLevel level = mongoTemplate.findOne(query, UserLevel.class);
        return level;
    }

    @Override
    public void updateUserLevel(Long userId, int i) {
        Query query = new Query(Criteria.where("uid").is(userId));
        Update update = new Update();
        update.set("Level",i);
        mongoTemplate.updateFirst(query,update,UserLevel.class);
    }
}
